package xsltrans;

//Based on http://xml.apache.org/xalan-j/usagepatterns.html

//JAXP classes
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.stream.StreamResult;

//JDK classes
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream; 

/**
 * Apply the XSL transform contained in the file named by the first command-line
 * argument to the XML document named by the second argument and write the
 * resulting document to standard output.
 */
class XSLTransform2File {
	// java XSLTransform HelloWorld.xsl HelloWorld.xml HolloWorld.html
	public static void main(String args[]) {
		try {
			PrintStream html_pr = new PrintStream(new FileOutputStream(new File(args[2])));  
			TransformerFactory tFactory = TransformerFactory.newInstance();
			Transformer transformer = tFactory.newTransformer(new StreamSource(
					new File(args[0]))); 
			transformer.setOutputProperty("indent", "yes"); 
			transformer.transform(new StreamSource(new File(args[1])),
					new StreamResult(html_pr));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return;
	}
}
